﻿using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using SharpDX;
using SharpDX.Direct2D1;
using SharpDX.DXGI;
using System.Drawing.Imaging;

using Factory = SharpDX.Direct2D1.Factory;
using AlphaMode = SharpDX.Direct2D1.AlphaMode;
using Bitmap = SharpDX.Direct2D1.Bitmap;
using PixelFormat = SharpDX.Direct2D1.PixelFormat;

namespace SpaceBattle
{
    class SpaceBackground
    {
        public RenderTarget renderTarget = null;
        public Factory factory = null;

        private List<Bitmap> Layers = new List<Bitmap>();
        private const int LayersCount = 3;

        private RectangleF Viewport0 = new RectangleF();
        private DrawingPointF CenterPoint = new DrawingPointF();

        public SpaceBackground(RenderTarget renderTarget, Factory factory)
        {
            this.renderTarget = renderTarget;
            this.factory = factory;

            for (int i = 0; i < LayersCount; i++)
            {
                Layers.Add(Utilities.LoadFromFile(renderTarget, "../../images/space" + i + ".png"));
            }

            CenterPoint = new DrawingPointF(renderTarget.PixelSize.Width / 2, renderTarget.PixelSize.Height / 2);

            for (int i = 0; i < LayersCount; i++)
            {
                
            }

            Viewport0.Left = -(Layers[0].PixelSize.Width-renderTarget.PixelSize.Width)/2;
            Viewport0.Top = -(Layers[0].PixelSize.Height - renderTarget.PixelSize.Height) / 2;
            Viewport0.Right = Viewport0.Left + Layers[0].PixelSize.Width;
            Viewport0.Bottom = Viewport0.Top + Layers[0].PixelSize.Height;
        }

        public void Update(float millisecondsElapsed)
        {
                       
        }

        public void Draw()
        {
            if (isResized == false)
            {
                for (int i = 0; i < Layers.Count; i++)
                {
                    renderTarget.DrawBitmap(Layers[i], Viewport0, 1.0f, BitmapInterpolationMode.Linear);
                }
            }
        }

        public void SetRectangle(RectangleF rect)
        {
            Viewport0 = rect;
            isResized = true;
        }

        public void ResetRectangle()
        {
            isResized = false;
        }

        private bool isResized = false;
    }
}